package com.example.droolstest.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.droolstest.entity.BusinessProperty;
import com.example.droolstest.service.BusinessPropertyService;
import com.example.droolstest.util.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/businessProperty")
public class BusinessPropertyController {

    @Autowired
    private BusinessPropertyService businessPropertyService;

    @PostMapping("/add")
    public AjaxResult addBusinessProperty(@RequestBody BusinessProperty businessProperty) {
        businessPropertyService.addBusinessProperty(businessProperty);
        return AjaxResult.success();
    }

    @GetMapping("")
    public AjaxResult getRuleProperty(Integer businessRuleTempId) {
        List<BusinessProperty> properties = businessPropertyService.list(
                new QueryWrapper<BusinessProperty>()
                        .eq(BusinessProperty.COL_BUSINESS_RULE_TEMP_ID, businessRuleTempId)
        );
        return AjaxResult.success(properties);
    }

    @PostMapping("/del")
    public AjaxResult delRuleProperty(Integer id){
        businessPropertyService.removeById(id);
        return AjaxResult.success();
    }
}
